package com.heakey.common.exception;

import com.heakey.common.constant.CommonConstant;
import lombok.Getter;
import lombok.Setter;

/**
 * @Description 业务异常
 * @Author Bing
 * @Date 2024/10/10 14:08
 */
@Getter
@Setter
public class BusinessException extends RuntimeException{

    private Integer code;

    private String message;

    public BusinessException(Integer code,String message){
        super(message);
        this.code = code;
        this.message = message;
    }

    public BusinessException(String message) {
        super(message);
        this.code = CommonConstant.DEFAULT_ERROR_CODE;
        this.message = message;
    }

    public static void throwBusException(String message){
        throw instance(CommonConstant.DEFAULT_ERROR_CODE,message);
    }

    public static void throwBusException(Integer code, String message){
        throw instance(code, message);
    }

    private static BusinessException instance(Integer errorCode, String message){
        return new BusinessException(errorCode,message);
    }
}